<script type="text/html" template>
	<link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

	<div class="layadmin-user-login-main">
		<div class="layadmin-user-login-box layadmin-user-login-header">
			<h2>eLab 智慧管理中台</h2>
			<p>致力于让科研 安全、智能、效率</p>
		</div>
		<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="userPhone"></label>
				<input type="text" name="userPhone" id="userPhone" maxlength="11" lay-verify="required" placeholder="用户手机号" class="layui-input">
			</div>
			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
				<input type="password" name="password" id="password" maxlength="20" lay-verify="required" placeholder="密码" class="layui-input">
			</div>
<!--      <div class="layui-form-item">-->
<!--        <div class="layui-row">-->
<!--          <div class="layui-col-xs7">-->
<!--            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="vercode"></label>-->
<!--            <input type="text" name="vercode" id="vercode" placeholder="图形验证码" class="layui-input">-->
<!--          </div>-->
<!--          <div class="layui-col-xs5">-->
<!--            <div style="margin-left: 10px;">-->
<!--              <img src="https://www.oschina.net/action/user/captcha" class="layadmin-user-login-codeimg" id="img-vercode">-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
			<div class="layui-form-item" style="margin-bottom: 20px;">
				<input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
				<a lay-href="/user/forget" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
			</div>
			<div class="layui-form-item">
				<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
			</div>
			<div class="layui-trans layui-form-item layadmin-user-login-other">
				<a lay-href="/user/reg" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
			</div>
		</div>
	</div>
  
	<div class="layui-trans layadmin-user-login-footer">
		<p>© 2021 <a href="http://www.efficientlab.cn/" target="_blank">efficientlab.cn</a></p>
	</div>
</div>

<script>
layui.use(['admin', 'form', 'user'], function() {
	var $ = layui.$;
	var setter = layui.setter;
	var admin = layui.admin;
	var form = layui.form;
	var router = layui.router();
	var search = router.search;

	form.render();

	//提交
	form.on('submit(LAY-user-login-submit)', function(obj) {

		$.ajax({
			url: layui.setter.baseUrl + '/JwtAPI/Auth/AccountLogin', //实际使用请改成服务端真实接口
			method: 'get',
			data: {
				phone: $('#userPhone').val(),
				password: $('#password').val(),
				clientType: 1
			},
			success: function (res) {
				// 请求成功后，写入 access_token
				if (res.success) {
					layui.data(setter.tableName, {
						key: setter.request.tokenName,
						value: 'bearer ' + res.token.refresh_access_token.refresh_token
					});
			
					// 登入成功的提示与跳转
					layer.msg('登入成功', {
						offset: '15px',
						icon: 1,
						time: 1000
					}, function(){
						location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/';
					});
				} else {
					// 登入失败
					layer.msg(res.msg, {
						offset: '15px',
						icon: 2,
						time: 1000
					});
				}
			}
		});
	});
});
</script>